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

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

m = A("m")
l = B("l")
n = A("n")
f = B("f")
e = A("e")
d = A("d")
g = A("g")
h = B("h")
k = B("k")

m.u = d
l.r = k
l.q = k
n.u = e
f.r = h
f.q = h
e.u = n
d.u = n
g.u = e
h.r = k
h.q = k
k.r = f
k.q = l
assert h.r.r.q.txt == "
class A:
    def __init__(self, txt: str):
        self.u: A = None
        self.txt = txt

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

m = A("m")
l = B("l")
n = A("n")
f = B("f")
e = A("e")
d = A("d")
g = A("g")
h = B("h")
k = B("k")

m.u = d
l.r = k
l.q = k
n.u = e
f.r = h
f.q = h
e.u = n
d.u = n
g.u = e
h.r = k
h.q = k
k.r = f
k.q = l
assert h.r.r.q.txt == "h"