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

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

j = A("j")
e = B("e")
d = B("d")
g = A("g")

j.t = g
e.v = j
e.p = j
d.v = g
d.p = g
g.t = j
assert g.t.t.t.txt == "
class A:
    def __init__(self, txt: str):
        self.t: A = None
        self.txt = txt

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

j = A("j")
e = B("e")
d = B("d")
g = A("g")

j.t = g
e.v = j
e.p = j
d.v = g
d.p = g
g.t = j
assert g.t.t.t.txt == "j"