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

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

e = A("e")
d = B("d")
c = A("c")
j = B("j")
b = A("b")
m = B("m")
f = A("f")

e.z = c
d.v = e
d.q = b
c.z = f
j.v = e
j.q = c
b.z = f
m.v = b
m.q = e
f.z = e
assert d.q.z.z.z.z.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.txt = txt

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

e = A("e")
d = B("d")
c = A("c")
j = B("j")
b = A("b")
m = B("m")
f = A("f")

e.z = c
d.v = e
d.q = b
c.z = f
j.v = e
j.q = c
b.z = f
m.v = b
m.q = e
f.z = e
assert d.q.z.z.z.z.z.z.txt == "c"