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

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

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

f.z = d
b.z = f
b.r = c
d.z = f
d.r = a
a.z = f
a.r = e
c.z = f
c.r = b
e.z = f
e.r = h
n.z = f
n.r = d
h.z = f
h.r = d
assert f.z.r.z.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.txt = txt

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

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

f.z = d
b.z = f
b.r = c
d.z = f
d.r = a
a.z = f
a.r = e
c.z = f
c.r = b
e.z = f
e.r = h
n.z = f
n.r = d
h.z = f
h.r = d
assert f.z.r.z.z.z.txt == "f"