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

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

f = A("f")
g = B("g")
a = A("a")
l = B("l")
j = B("j")

f.t = a
f.z = l
g.w = f
a.t = f
a.z = l
l.w = f
j.w = a
assert g.w.z.w.txt == "
class A:
    def __init__(self, txt: str):
        self.t: A = None
        self.z: B = None
        self.txt = txt

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

f = A("f")
g = B("g")
a = A("a")
l = B("l")
j = B("j")

f.t = a
f.z = l
g.w = f
a.t = f
a.z = l
l.w = f
j.w = a
assert g.w.z.w.txt == "f"