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

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

f = A("f")
d = B("d")
c = B("c")
e = A("e")
g = B("g")

f.z = e
f.r = e
d.v = g
c.v = d
e.z = f
e.r = f
g.v = d
assert c.v.v.v.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.r: A = None
        self.txt = txt

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

f = A("f")
d = B("d")
c = B("c")
e = A("e")
g = B("g")

f.z = e
f.r = e
d.v = g
c.v = d
e.z = f
e.r = f
g.v = d
assert c.v.v.v.txt == "d"