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

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

l = A("l")
d = B("d")
b = A("b")
g = B("g")
j = B("j")
h = A("h")

l.r = d
l.t = b
d.u = b
d.p = j
b.r = d
b.t = h
g.u = b
g.p = d
j.u = h
j.p = d
h.r = j
h.t = b
assert j.u.r.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.t: A = None
        self.txt = txt

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

l = A("l")
d = B("d")
b = A("b")
g = B("g")
j = B("j")
h = A("h")

l.r = d
l.t = b
d.u = b
d.p = j
b.r = d
b.t = h
g.u = b
g.p = d
j.u = h
j.p = d
h.r = j
h.t = b
assert j.u.r.p.p.txt == "j"