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

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

j = A("j")
f = B("f")
d = B("d")
h = B("h")
l = B("l")
n = A("n")

j.t = f
f.u = h
f.q = h
d.u = l
d.q = h
h.u = f
h.q = f
l.u = h
l.q = f
n.t = h
assert j.t.q.u.u.q.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.txt = txt

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

j = A("j")
f = B("f")
d = B("d")
h = B("h")
l = B("l")
n = A("n")

j.t = f
f.u = h
f.q = h
d.u = l
d.q = h
h.u = f
h.q = f
l.u = h
l.q = f
n.t = h
assert j.t.q.u.u.q.txt == "f"