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

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

b = A("b")
e = B("e")
d = B("d")
j = A("j")
c = A("c")
k = A("k")
h = A("h")
a = B("a")
f = A("f")

b.x = j
b.q = c
e.u = k
e.r = d
d.u = j
d.r = e
j.x = b
j.q = k
c.x = b
c.q = f
k.x = f
k.q = f
h.x = f
h.q = j
a.u = h
a.r = d
f.x = c
f.q = j
assert d.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.q: A = None
        self.txt = txt

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

b = A("b")
e = B("e")
d = B("d")
j = A("j")
c = A("c")
k = A("k")
h = A("h")
a = B("a")
f = A("f")

b.x = j
b.q = c
e.u = k
e.r = d
d.u = j
d.r = e
j.x = b
j.q = k
c.x = b
c.q = f
k.x = f
k.q = f
h.x = f
h.q = j
a.u = h
a.r = d
f.x = c
f.q = j
assert d.r.r.r.txt == "e"