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

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

b = A("b")
e = B("e")
c = A("c")
g = A("g")

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

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

b = A("b")
e = B("e")
c = A("c")
g = A("g")

b.y = c
e.z = g
e.v = c
c.y = b
g.y = c
assert b.y.y.y.y.txt == "b"