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

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

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

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

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

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

m.w = g
m.y = j
e.t = m
g.t = m
j.w = g
j.y = m
assert g.t.w.t.txt == "m"