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

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

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

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

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

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

e.t = d
e.v = j
d.w = g
d.q = j
g.t = d
g.v = e
j.t = d
j.v = g
assert j.v.v.t.txt == "d"