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

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

c = A("c")
j = B("j")
a = B("a")
b = A("b")
g = A("g")

c.p = j
c.r = a
j.u = c
j.z = b
a.u = c
a.z = g
b.p = a
b.r = a
g.p = j
g.r = j
assert c.r.u.r.z.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.r: B = None
        self.txt = txt

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

c = A("c")
j = B("j")
a = B("a")
b = A("b")
g = A("g")

c.p = j
c.r = a
j.u = c
j.z = b
a.u = c
a.z = g
b.p = a
b.r = a
g.p = j
g.r = j
assert c.r.u.r.z.p.txt == "j"