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

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

f = A("f")
a = B("a")
d = B("d")
g = A("g")

f.t = d
f.y = d
a.p = d
d.p = a
g.t = a
g.y = a
assert f.t.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.y: B = None
        self.txt = txt

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

f = A("f")
a = B("a")
d = B("d")
g = A("g")

f.t = d
f.y = d
a.p = d
d.p = a
g.t = a
g.y = a
assert f.t.p.p.p.txt == "a"