class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.o: B = None
        self.r: B = None
        self.txt = txt

g = A("g")
j = B("j")
m = A("m")
c = A("c")
n = B("n")
f = A("f")
a = B("a")

g.q = a
j.o = n
j.r = n
m.q = j
c.q = a
n.o = a
n.r = j
f.q = n
a.o = n
a.r = j
assert a.r.o.o.r.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.o: B = None
        self.r: B = None
        self.txt = txt

g = A("g")
j = B("j")
m = A("m")
c = A("c")
n = B("n")
f = A("f")
a = B("a")

g.q = a
j.o = n
j.r = n
m.q = j
c.q = a
n.o = a
n.r = j
f.q = n
a.o = n
a.r = j
assert a.r.o.o.r.txt == "j"