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

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

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

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

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

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

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